import request from "../utils/request";

export function loginApi(username: string, password: string) {
  return new Promise((resolve) => {
    uni.request({
      url: "http://localhost:3000/api/users/login", // 根据你的后端端口和路径调整
      method: "POST",
      data: { username, password },
      success: (res: any) => resolve(res.data),
      fail: () => resolve({ code: 1, msg: "网络错误" }),
    });
  });
}

export function registerApi(username: string, password: string) {
  return new Promise((resolve) => {
    uni.request({
      url: "http://localhost:3000/api/users/register",
      method: "POST",
      data: { username, password },
      success: (res: any) => resolve(res.data),
      fail: () => resolve({ code: 1, msg: "网络错误" }),
    });
  });
}
